fl.outputPanel.clear();
scanLibrary(fl.getDocumentDOM().library);



function getIsWholeInt(n)
{
	var s = String(n);
	if(s.indexOf(".") != -1)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function round(n)
{
	var s = String(n);
	var a = s.split(".");
	var num = parseInt(a[0]);
	var dec = parseInt(a[1].substr(0, 1));
	if(dec >= 5)
	{
		num++;
	}
	return num;
}

/**
 * Scans the supplied flash library for linked classes and makes sure the textfields are set up properly
 * @param 	library		A flash library to scan.
 */
function scanLibrary(library)
{
    var items = library.items;
    var item;
	var replaceCount = 0;
  
    for( var i = 0; i < items.length; i++ )
    {
        item = items[i];
		if (item.itemType == 'movie clip') 
		{
			var timeline = item.timeline;
			var h = timeline.layerCount;
			
			library.selectItem(item);
			library.editItem();
			
			while(h--)
			{
				var k = timeline.layers[h].frameCount;
				
				while(k--)
				{
					var j = timeline.layers[h].frames[k].elements.length;
					
					while(j--)
					{
						var elems = timeline.layers[h].frames[k].elements;
						var p = elems.length;
						
						while(p--)
						{
							if(elems[p].elementType == "text" && (elems[p].textType == "dynamic" || elems[p].textType == "input"))
							{
								//Change the Static Text Fields to Dynamic
								if(elems[p].textType == "static") {
									elems[p].textType = "dynamic";
								}
								
								//Handle all Dynamic TextFields
								if(elems[p].textType == "dynamic") {
									//Remove the ability to be selectable
									elems[p].selectable = false;
								}
								
								//Handle all Dynamic or Input Textfields
								
								//Remove the auto kern attribute
								elems[p].setTextAttr('autoKern', false);
								//Embed fonts UpperCase, LowerCase, Numerals, Punctuation
								elems[p].embedRanges = "1|2|3|4";
								
								//Pop onto whole pixel
								var matX = elems[p].matrix;
								var x = matX.tx;
								if(!getIsWholeInt(x))
								{
									matX.tx = round(x);
									elems[p].matrix = matX;
								}
								
								var matY = elems[p].matrix;
								var y = matY.ty;
								if(!getIsWholeInt(y))
								{
									matY.ty = round(y);
									elems[p].matrix = matY;
								}
			
							}
						}
						
					}

				}
			}
		}
    }
}

